package com.i2863.tools.weixinmp.util;

import com.alibaba.fastjson.JSON;
import redis.clients.jedis.Jedis;

/**
 * @author xuweiwei
 * @date 2018/1/8
 */
public class RedisQueueUtils {
    public static String pop(String key) {
        Jedis jedis = null;
        try {
            jedis = RedisPool.getJedis();
            return jedis.lpop(key);
        } finally {
            RedisPool.close(jedis);
        }
    }

    public static void push(String key,String value) {
        Jedis jedis = null;
        try {
            jedis = RedisPool.getJedis();
             jedis.rpush(key,value);
        } finally {
            RedisPool.close(jedis);
        }
    }

    public static void insert(String key,String value) {
        Jedis jedis = null;
        try {
            jedis = RedisPool.getJedis();
            jedis.lpush(key,value);
        } finally {
            RedisPool.close(jedis);
        }
    }

    public static void push(String key,Object obj){
        push(key,JSON.toJSONString(obj));
    }

    public static void insert(String key,Object obj){
        insert(key,JSON.toJSONString(obj));
    }
    public static long count(String key){
        Jedis jedis = null;
        try {
            jedis = RedisPool.getJedis();
            return jedis.llen(key);
        } finally {
            RedisPool.close(jedis);
        }
    }
    public static void main(String[] args) {
        System.out.println(count("weixin:code"));
    }
}
